<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">



    <div class="layui-form-item">
        <label class="layui-form-label">角色名</label>
        <div class="layui-input-block">
            <input type="text" name="name" required  lay-verify="required" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" name="description" required  lay-verify="required" placeholder="请输入角色描述" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js"></script>
<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer=layui.layer;//弹出层
        var $=layui.jquery;
        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            //提交Ajax请求
            $.ajax({
                url:"/addRole",
                type:"GET",
                dateType:"JSON",
                data:data.field,
                success:function (data) {
                    if (data.code == "0") {
                        //获取弹出窗口的id
                        var frameIndex = parent.layer.getFrameIndex(window.name);
                        //关闭弹出窗口
                        parent.layer.close(frameIndex);
                        //重新加载表格
                        parent.layui.table.reload("demo");
                    } else {
                        layer.alert("角色名称已存在！");
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>